﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CashierSystem.CashierInManager;
using CashierSystem.UserManager;

namespace CashierSystem.CustomerManager
{
    public partial class SearchOldCustomerForm : Form
    {
        User user;
        public SearchOldCustomerForm(User user)
        {
            this.user = user;
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count != 1)
            {
                DialogResult response = MessageBox.Show("请选择一条记录！");
                return;

            }
            else
            {
                string regNo = listView1.SelectedItems[0].SubItems[0].Text;
                CashierInForm cif = new CashierInForm(regNo, user);
                cif.StartPosition = FormStartPosition.CenterScreen;
                cif.ShowDialog();
            }
        }



        private void button2_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count != 1)
            {
                DialogResult response = MessageBox.Show("请选择一条记录！");
                return;

            }
            else
            {
                string customerId = listView1.SelectedItems[0].SubItems[0].Text;
                GetRegInForm grif = new GetRegInForm(customerId, user);
                grif.StartPosition = FormStartPosition.CenterScreen;
                grif.ShowDialog();
            }

        }

        private void SearchOldCustomerForm_Load(object sender, EventArgs e)
        {
            string customerName = tbCustomerName.Text;
            string customerType = cbCustomerType.Text;
            string workPlace = tbWorkPlace.Text;
            string startDate = tbStartDate.Text;
            string endDate = tbEndDate.Text;
            CustomerManagerAction.loadCustomers(listView1, customerName, customerType, workPlace,startDate,endDate);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string customerId = listView1.SelectedItems[0].SubItems[0].Text;
            SaleCardForm scf = new SaleCardForm(user,customerId);
            scf.StartPosition = FormStartPosition.CenterScreen;
            scf.ShowDialog();
        }

        private void dtpStartDate_ValueChanged(object sender, EventArgs e)
        {
            tbStartDate.Text = dtpStartDate.Value.Date.ToString();
        }

        private void dtpEndDate_ValueChanged(object sender, EventArgs e)
        {
            tbEndDate.Text = dtpEndDate.Value.Date.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string customerType = cbCustomerType.Text;
            string customerName = tbCustomerName.Text;
            string workPlace = tbWorkPlace.Text;
            string startDate = tbStartDate.Text;
            string endDate = tbEndDate.Text;

            CustomerManagerAction.loadCustomers(listView1, customerName, customerType, workPlace, startDate, endDate);
        }


    }
}